#!/bin/bash

# This wrapper script is necessary in order to hide the gory details of how
# to deal with the Android NDK when using autotools.

sysroot_compile=@sysroot_compile@
sysroot_link=@sysroot_link@
sysinc=@sysinc@

argv=()
mode=link

for arg in "$@"; do
  case "$arg" in
    -E|-c)
      mode=compile
      ;;
  esac

  argv+=("$arg")
done

case $mode in
  compile)
    argv+=("--sysroot=$sysroot_compile" "-isystem" "$sysinc")
    ;;
  link)
    argv+=("--sysroot=$sysroot_link")
    ;;
esac

exec "${argv[@]}"
